#include "logo.h"

char *last(void)
{
     int i;
     int k;
     char *ans;
     char *val;
     char *ansr;
     char ansrStr[MAXVALUE] ="\0";
     char valStr[MAXVALUE] ="\0";
     char ansStr[MAXVALUE] ="\0";

     val =valStr;
     ans =ansStr;
     ansr =ansrStr;
     strcpy(val,getValue());
     printf("string of last is %s\n",val);
     if (val[0] == '[')
     {
        i=strlen(val)-2;
        k=0;
        while (i>0)
        {
              if ((!k)&&(i<strlen(val)-2)&&((val[i] ==' ')||(val[i] ==']')))
              {
                 break;
              }else if (val[i] ==']')
              {
                    k++;
              }else if (val[i] =='[')
              {
                    k--;
              }
              printf("char of last is %c,%d\n",val[i],k);
              ansr[strlen(ansr)+1]='\0';
              ansr[strlen(ansr)] =val[i];
              i--;
        }
        if (ansr[strlen(ansr)-1] == '\"')
        {
           ansr[strlen(ansr)-1] ='\0';
        }
        for (i=0;i<strlen(ansr);i++)
        {
            ans[i+1] ='\0';
            ans[i] =ansr[strlen(ansr)-i-1];
        }
        goto RE;
     }
     ans[1] ='\0';
     ans[0] =val[strlen(val)-1];
     RE:
            return ans;

}
